package com.huanf.exception;

import com.huanf.enums.SystemEnum;
import com.huanf.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
//全局异常处理
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExceptionHandler(SystemException e){
        log.error("出现了异常! {}",e);
        return ResponseResult.fail(e.getCode(),e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHandler(Exception e){
        log.error("出现了异常! {}",e);
        return ResponseResult.fail(SystemEnum.FAIL.getCode(),e.getMessage());
    }
}